package com.dmgis.qxfw.dataservice.businessservice.yyhb.controller;

import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.msgmediumsmallscale;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.CloudSearch;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.MsgMediumSmallScale;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.RadarSearch;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.Doppler;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.DopplerKey;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.SatelliteNephoramKey;
import com.dmgis.qxfw.dataservice.businessservice.common.pojo.AirPolLiveQX;
import com.dmgis.qxfw.dataservice.businessservice.common.pojo.ImportantWeather;
import com.dmgis.qxfw.dataservice.businessservice.common.pojo.SatelliteNephoram;
import com.dmgis.qxfw.dataservice.businessservice.common.service.IConfigService;
import com.dmgis.qxfw.dataservice.businessservice.common.util.DateTime;
import com.dmgis.qxfw.dataservice.businessservice.common.util.FileUtil;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.MongoService1;
import com.dmgis.qxfw.dataservice.businessservice.yyhb.service.MeteInfoServiceI;
import com.github.kevinsawicki.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/xthb")
public class MeteInfoController {
	private  final String operatingSystem;

	@Autowired
	public MeteInfoController(String operatingSystem) {
		this.operatingSystem = operatingSystem;
	}

	@Autowired
	private MeteInfoServiceI serviceI;
	@Resource
	private IConfigService configService;


	MongoService1 ms = new MongoService1();

	/* 初始化雷达图界面 */
	@RequestMapping("/initReaderPage")
	@ResponseBody
	public Object initReaderPage() {
		ArrayList<Object> arrayList = new ArrayList<Object>();/* object各种类型数据 */
		DopplerKey newestDate = serviceI.getReaderNewDate();
		// 加载列表
		String timechar = newestDate.getTimeChar();
		DateTime datechar = new DateTime(newestDate.getDateChar());// DateTime类型
		datechar = datechar.AddHours(Integer.parseInt(timechar.substring(0, 2)));// 将指定的时间加到上面
		String startDate = datechar.AddHours(-1).toDateTimeString();// String类型
		String endDate = datechar.toDateTimeString();// String类型
		arrayList.add(startDate);// 开始时间
		arrayList.add(endDate);// 结束时间

		arrayList.add(configService.getSysConfig("雷达站"));// 添加雷达站信息,getSysConfig获取系统信息
		List<DopplerKey> dopplerkey = serviceI.getRadarTypes();
		arrayList.add(dopplerkey);
		return arrayList;
	}

	/* 获得雷达图 */
	@RequestMapping("/getRadar")
	@ResponseBody
	public Object getRadar(HttpServletRequest request, Model model) {
		RadarSearch selectKey = new RadarSearch();// 查询类
		String startDate = request.getParameter("startDate");// 开始时间
		String endDate = request.getParameter("endDate");// 结束时间
		String type = request.getParameter("type");// 类型
		String elevation = request.getParameter("elevation");// 仰角
		String stationId = request.getParameter("stationId");// 站点
		selectKey.setStartDate(startDate);
		selectKey.setEndDate(endDate);
		selectKey.setType(type);
		selectKey.setElevation(Float.parseFloat(elevation));
		selectKey.setStationId(stationId);

		List<Doppler> resultList = serviceI.getRadar(selectKey); // 雷达结果
		String urlpath ;
		if (operatingSystem.equals("Windows")){
			 urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Radar\\";// 临时文件目录
		}else {
			 urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/Radar/";// 临时文件目录
		}

		FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
		FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
		for (Doppler doppler : resultList) {//
			String fileName = DbConfig.getRadarFileName(doppler.getType(), String.valueOf(doppler.getElevation()),
					doppler.getStationId(), doppler.getDateChar(), doppler.getTimeChar()) + ".jpg";
			String servicePath = urlpath + fileName;// 服务器文件
			File serviceFile = new File(servicePath);// 服务器文件
			if (serviceFile.exists()) {// 把文件上传到服务器
				if (operatingSystem.equals("Windows")){
					doppler.setJwImgPath("Temp\\Radar\\" + fileName);
				}else {
					doppler.setJwImgPath("Temp/Radar/" + fileName);
				}

			} else {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("datechar", new DateTime(doppler.getDateChar()).toDateString());
				map.put("stationid", doppler.getStationId());
				double elev = doppler.getElevation();
				String elevString = (doppler.getElevation() - (int) elev) == 0 ? String.valueOf((int) elev)
						: String.valueOf(doppler.getElevation());
				map.put("elevation", elevString);
				map.put("ldtype", doppler.getType());
				map.put("timechar", doppler.getTimeChar());
				map.put("collectionName", "ld_png_file");
				map.put("advCode", DbConfig.advCode);
				byte[] data = ms.selectData(map);
				FileUtil.bytesToFile(data, servicePath);
				if (operatingSystem.equals("Windows")){
					doppler.setJwImgPath("Temp\\Radar\\" + fileName);
				}else {
					doppler.setJwImgPath("Temp/Radar/" + fileName);
				}
			}
		}
		return resultList;
	}

	/* 初始化云图界面 */
	@RequestMapping("/initSatellitePage")
	@ResponseBody
	public Object initSatellitePage() {
		ArrayList<Object> arrayList = new ArrayList<Object>();/* object各种类型数据 */
		SatelliteNephoramKey newestDate = serviceI.getCloudNewDate();
		// 加载列表
		DateTime datechar = new DateTime(newestDate.getDateChar());// DateTime类型
		String startDate = datechar.AddDays(-1).toDateString();// 开始时间
		String endDate = datechar.toDateString();// 结束时间
		arrayList.add(startDate);// 开始时间
		arrayList.add(endDate);// 结束时间
		List<SatelliteNephoramKey> satelliteNephoramKey = serviceI.getCloudTypes();
		arrayList.add(satelliteNephoramKey);// 云图类型
		return arrayList;
	}

	/* 获得云图 */
	@RequestMapping("/getCloud")
	@ResponseBody
	public Object getCloud(HttpServletRequest request, Model model) {
		CloudSearch selectKey = new CloudSearch();// 查询类
		String startDate = request.getParameter("startDate");// 开始时间
		String endDate = request.getParameter("endDate");// 结束时间
		String type = request.getParameter("type");// 类型
		selectKey.setStartDate(startDate);
		selectKey.setEndDate(endDate);
		selectKey.setType(type);
		List<SatelliteNephoram> resultList = serviceI.getCloud(selectKey); // 雷达结果
		String urlpath ;
		if (operatingSystem.equals("Windows")){
			 urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Cloud\\";// 临时文件目录
		}else {
			 urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/Cloud/";// 临时文件目录
		}

		FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
		FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
		for (SatelliteNephoram satelliteNephoram : resultList) {
			String fileName = DbConfig.getYtFileName(satelliteNephoram.getType(), satelliteNephoram.getDateChar(),
					satelliteNephoram.getTimechar()) + ".jpg";
			String servicePath = urlpath + fileName;// 服务器路径
			File serviceFile = new File(servicePath);// 服务器文件
			if (serviceFile.exists()) {// 把文件上传到服务器
				if (operatingSystem.equals("Windows")){
					satelliteNephoram.setJwImgPath("Temp\\Cloud\\" + fileName);
				}else {
					satelliteNephoram.setJwImgPath("Temp/Cloud/" + fileName);
				}

			} else {
				Map<String, String> map = new HashMap<String, String>();
				map.put("datechar", new DateTime(satelliteNephoram.getDateChar()).toDateString());
				map.put("yttype", satelliteNephoram.getType());
				map.put("timechar", satelliteNephoram.getTimechar());
				map.put("collectionName", "yt_jpg_file");
				map.put("advCode", DbConfig.advCode);
				byte[] data = HttpRequest.get(DbConfig.mongoSelectUrl, map, true).bytes();
				FileUtil.bytesToFile(data, servicePath);
				if (operatingSystem.equals("Windows")){
					satelliteNephoram.setJwImgPath("Temp\\Cloud\\" + fileName);
				}else {
					satelliteNephoram.setJwImgPath("Temp/Cloud/" + fileName);
				}
			}
		}
		return resultList;
	}

	/**
	 *要素查询的站点id
	 * @return
	 */
	public List<String> initStations() {
		List<String> resultList = serviceI.initStations();
		return resultList;
	}

	/**
	 * 查询气象要素
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getLiveElement")
	@ResponseBody
	public String getLiveElement(HttpServletRequest request) throws Exception {
		String startTime = request.getParameter("startTime") + " 00:00:00";
		String endTime = request.getParameter("endTime") + " 23:59:59";
		String type = request.getParameter("type").trim();
		String hourOrDay = request.getParameter("hourOrDay").trim();
//		String[] stationNames = request.getParameterValues("stationName");
		List<String> stringList = stringList = initStations();

		String element = request.getParameter("element").trim();
		String ele = "";
		String xValue = "[";
		String listData = "[";
		Field field = null;
		if (!"drybulbtemp".equals(element)) {
			if (hourOrDay.contains("时")) {
				field = msgmediumsmallscale.class.getDeclaredField(element);
			} else {
				field = MsgMediumSmallScale.class.getDeclaredField(element);
			}
			field.setAccessible(true);
		}
		switch (element) {
		case "instantwindv":
			ele = "风速";
			break;
		case "drybulbtemp":
			ele = "温度";
			break;
		case "rain":
			ele = "降水量";
			break;
		case "cloud":
			ele = "云量";
			break;
		case "maxtemp":
			ele = "最高温度";
			break;
		case "mintemp":
			ele = "最低温度";
			break;
		case "relhumidity":
			ele = "相对湿度";
			break;
		case "visibility":
			ele = "能见度";
			break;
		}

		// 站点
		String stations = "(";
		for (String s : stringList) {
			stations += "'" + s + "'" + ",";
		}
		if (stations.endsWith(",")) {
			stations = stations.substring(0, stations.length() - 1);
		}
		stations = stations + ")";


		// 查询
		List<String> strList = new ArrayList<String>();
		List<msgmediumsmallscale> eleList = new ArrayList<msgmediumsmallscale>();
		List<MsgMediumSmallScale> eleListday = new ArrayList<MsgMediumSmallScale>();

		// 时效、x轴
		String tit = "";
		String dates = "(";
		if (dates.endsWith(",")) {
			dates = dates.substring(0, dates.length() - 1);
		}
		dates = dates + ")";
		if (hourOrDay.contains("时")) {
			eleList = serviceI.getMsgMediumSmallScale(startTime, endTime, hourOrDay, stations);
			for (int i = 0; i < eleList.size(); i ++) {
				DateTime dt = new DateTime(eleList.get(i).getObservtime());
				xValue += "'" + dt.toDateString() + " " + dt.GetHour() + "',";
			}
			tit = "24";
			if (xValue.endsWith(",")) {
				xValue = xValue.substring(0, xValue.length() - 1);
			}
			xValue = xValue + "]";
			if(stringList!=null && stringList.size()>0) {
				for (String s : stringList) {
					String name = s.trim();
					String yValue = "{name:'" + name + "',data:" + "[";
					for (msgmediumsmallscale me : eleList) {
						if (me.getStationname().trim().equals(name)) {
							switch (element) {
								case "instantwindv":
									if (me.getInstantwindv() != -65535) {
										yValue += me.getInstantwindv() + ",";
									}
									break;
								case "drybulbtemp":
									if (me.getMaxtemp() != -65535) {
										yValue += ((me.getMaxtemp() + me.getMintemp()) / 2) + ",";
									}
									break;
								case "rain":
									if (me.getRain() != -65535) {
										yValue += me.getRain() + ",";
									}
									break;
								case "cloud":
									if (me.getCloud() != null && me.getCloud() != -65535) {
										yValue += me.getCloud() + ",";
									}
									break;
								case "maxtemp":
									if (me.getMaxtemp() != -65535) {
										yValue += me.getMaxtemp() + ",";
									}
									break;
								case "mintemp":
									if (me.getMintemp() != -65535) {
										yValue += me.getMintemp() + ",";
									}
									break;
								case "relhumidity":
									if (me.getRelhumidity() != -65535) {
										yValue += me.getRelhumidity() + ",";
									}
									break;
								case "visibility":
									if (me.getVisibility() != -65535) {
										yValue += me.getVisibility() + ",";
									}
									break;
							}
						}
						DateTime dt = new DateTime(me.getObservtime());
						if (!"drybulbtemp".equals(element)) {
							listData += "{\"station\":\"" + me.getStationname() + "\",\"date\":\"" + dt.toDateString() + " "
									+ dt.GetHour() + "\",\"other\":\"" + field.get(me) + "\"},";
						} else {
							listData += "{\"station\":\"" + me.getStationname() + "\",\"date\":\"" + dt.toDateString() + " "
									+ dt.GetHour() + "\",\"other\":\"" + me.getDrybulbtemp() + "\"},";
						}
					}
					if (yValue.endsWith(",")) {
						yValue = yValue.substring(0, yValue.length() - 1);
					}
					yValue = yValue + "]},";
					strList.add(yValue);
					yValue = "";
				}
			}
		} else {
			eleListday = serviceI.getMediumSmallScale(startTime, endTime, hourOrDay, stations);
			for (int i = 0; i < eleListday.size(); i ++) {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				DateTime dt = new DateTime(sdf.parse(eleListday.get(i).getDatechar()));
				xValue += "'" + dt.toDateString() + "',";
			}
			tit = "31";
			if (xValue.endsWith(",")) {
				xValue = xValue.substring(0, xValue.length() - 1);
			}
			xValue = xValue + "]";
			if(stringList!=null&&stringList.size()>0) {
				for (String s : stringList) {
					String name = s.trim();
					String yValue = "{name:'" + name + "',data:" + "[";
					for (MsgMediumSmallScale me : eleListday) {
						if (me.getStationname().trim().equals(name)) {
							switch (element) {
								case "instantwindv":
									if (me.getInstantwindv() != -65535 && me.getInstantwindv() > 0) {
										yValue += me.getInstantwindv() + ",";
									}
									break;
								case "drybulbtemp":
									if (me.getMaxtemp() != -65535 && me.getMintemp() != -65535) {
										yValue += ((me.getMaxtemp() + me.getMintemp()) / 2) + ",";
									}
									break;
								case "rain":
									if (me.getRain() != -65535) {
										yValue += me.getRain() + ",";
									}
									break;
								case "cloud":
									if (me.getCloud() != null && me.getCloud() != -65535) {
										yValue += me.getCloud() + ",";
									}
									break;
								case "maxtemp":
									if (me.getMaxtemp() != -65535) {
										yValue += me.getMaxtemp() + ",";
									}
									break;
								case "mintemp":
									if (me.getMintemp() != -65535) {
										yValue += me.getMintemp() + ",";
									}
									break;
								case "relhumidity":
									if (me.getRelhumidity() != -65535 && me.getRelhumidity() > 0) {
										yValue += me.getRelhumidity() + ",";
									}
									break;
							}
						}
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
						DateTime dt = new DateTime(sdf.parse(me.getDatechar()));
						if (!"drybulbtemp".equals(element)) {
							listData += "{\"station\":\"" + me.getStationname() + "\",\"date\":\"" + dt.toDateString()
									+ "\",\"other\":\"" + field.get(me) + "\"},";
						} else {
							listData += "{\"station\":\"" + me.getStationname() + "\",\"date\":\"" + dt.toDateString()
									+ "\",\"other\":\"" + String.format("%.1f", (me.getMaxtemp() + me.getMintemp()) / 2) + "\"},";
						}
					}
					if (yValue.endsWith(",")) {
						yValue = yValue.substring(0, yValue.length() - 1);
					}
					yValue = yValue + "]},";
					strList.add(yValue);
					yValue = "";
				}
			}
		}

		String y = "[";
		for (String ss : strList) {
			y += ss;
		}
		if (y.endsWith(",")) {
			y = y.substring(0, y.length() - 1);
		}
		y = y + "]";
		if (tit.endsWith("-")) {
			tit = tit.substring(0, tit.length() - 1);
		}
		if (listData.endsWith(",")) {
			listData = listData.substring(0, listData.length() - 1);
		}
		listData = listData + "]";
		String title = "";
		if (hourOrDay.contains("时")) {
			title = "['" + startTime.substring(0, 4) + "年" + startTime.substring(5, 7) + "月"
					+ startTime.substring(8, 10) + "日" + startTime.substring(11, 13) + "时" + "至"
					+ endTime.substring(0, 4) + "年" + endTime.substring(5, 7) + "月" + endTime.substring(8, 10) + "日"
					+ endTime.substring(11, 13) + "时" + " " + ele + " " + tit + "小时曲线图" + "']";
		} else {
			title = "['" + startTime.substring(0, 4) + "年" + startTime.substring(5, 7) + "月"
					+ startTime.substring(8, 10) + "日" + "至" + endTime.substring(0, 4) + "年" + endTime.substring(5, 7)
					+ "月" + endTime.substring(8, 10) + "日" + " " + ele + " " + tit + "日曲线图" + "']";
		}
		String temp = xValue + "|" + y + "|" + title + "|['" + type + "']|" + listData + "|['" + ele + "']";
		return temp;
	}


	/**
	 * 雾霾能见度
	 * @param request
	 * @return
	 */
	@RequestMapping("/getHazeVisibility")
	@ResponseBody
	public String getHazeVisibility(HttpServletRequest request) {
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		List<ImportantWeather> iList = new ArrayList<ImportantWeather>();
		iList = serviceI.getHazeVisibility(startTime, endTime);
		String tableData = "[";
		for (ImportantWeather im : iList) {
			DateTime dt = new DateTime(im.getTime());
			tableData += "{\"stationId\":\"" + im.getStationId() + "\",\"stationName\":\"" + im.getStationName()
					+ "\",\"dateChar\":\"" + dt.toDateTimeString() + "\",\"type\":\"" + im.getWeatherType()
					+ "\",\"Describe\":\"" + im.getWeatherInfo() + "\"},";
		}
		if (tableData.endsWith(",")) {
			tableData = tableData.substring(0, tableData.length() - 1);
		}
		tableData = tableData + "]";
		return tableData;
	}

	/**
	 * 每日气象资料
	 * @return
	 */
	@RequestMapping("/dailyInitTime")
	@ResponseBody
	public String dailyInitTime() {
		Date date = serviceI.dailyInitTime();
		DateTime dt = new DateTime(date);
		return dt.toDateString();
	}


	/**
	 * 每日气象资料查询
	 * @return
	 */
	@RequestMapping("/getDailyWeather")
	@ResponseBody
	public String getDailyWeather(HttpServletRequest request) throws Exception {
		String startTime = request.getParameter("startTime");
		// 至
		String judge = "";
		if (request.getParameter("judge").equals("true")) {
			judge = "1";
		} else {
			judge = "0";
		}
		String endTime = request.getParameter("endTime");
		String station = request.getParameter("station");
		String element = request.getParameter("element");
		String ele = "";
		String type = request.getParameter("type");
		String xValue = "[";
		String yValue = "[";
		String ytitle = "";
		String title = "";
		if ("风速".equals(element.trim())) {
			ele = "WindS";
			ytitle = "风速（m/s）";
		} else if ("湿度".equals(element.trim())) {
			ele = "RelHumid";
			ytitle = "湿度 （%）";
		} else if ("降水".equals(element.trim())) {
			ele = "Rain";
			ytitle = "降水（mm）";
		} else if ("气压".equals(element.trim())) {
			ele = "Pressure";
			ytitle = "气压（hPa）";
		} else if ("云量".equals(element.trim())) {
			ele = "Cloud";
			ytitle = "云量(%)";
		} else if ("能见度".equals(element.trim())) {
			ele = "Visibility";
			ytitle = "能见度（m）";
		} else if ("最高气温".equals(element.trim())) {
			ele = "MaxTemp";
			ytitle = "最高气温(℃)";
		} else if ("最低气温".equals(element.trim())) {
			ele = "MinTemp";
			ytitle = "最低气温(℃)";
		} else if ("平均气温".equals(element.trim())) {
			ele = "DryBulbTemp";
			ytitle = "平均气温(℃)";
		}
		String listData = "[";
		String x = "";
		List<AirPolLiveQX> alist = new ArrayList<AirPolLiveQX>();
		if (judge.equals("1")) {
			title = "['" + startTime + "日至" + endTime + "日" + ytitle + "曲线图']";
			if (!"all".equals(station)) {
				alist = serviceI.getDailyWeather(ele, startTime, endTime, station.trim(), true);
			} else {
				alist = serviceI.getDailyWeather1(ele, startTime, endTime, true);
			}
		} else {
			title = "['" + startTime + "日" + ytitle + "曲线图']";
			if (!"all".equals(station)) {
				alist = serviceI.getDailyWeather(ele, startTime, endTime, station.trim(), false);
			} else {
				alist = serviceI.getDailyWeather1(ele, startTime, endTime, false);
			}
		}

		if (!"all".equals(station.trim())) {
			for (AirPolLiveQX aq : alist) {
				DateTime dt = new DateTime(aq.getObservTime());
				Field field = AirPolLiveQX.class.getDeclaredField(ele);
				xValue += "'" + dt.toDateTimeString("yyyy-MM-dd HH") + "',";
				field.setAccessible(true);
				yValue += field.get(aq) + ",";

				// 列表数据
				listData += "{\"stationId\":\"" + aq.getStationID() + "\",\"stationName\":\"" + aq.getStationName()
						+ "\",\"dateChar\":\"" + dt.toDateTimeString() + "\",\"other\":\"" + field.get(aq) + "\"},";
			}
			if (xValue.endsWith(",")) {
				xValue = xValue.substring(0, xValue.length() - 1);
			}
			xValue = xValue + "]";
			if (yValue.endsWith(",")) {
				yValue = yValue.substring(0, yValue.length() - 1);
			}
			yValue = yValue + "]";
			yValue = "[{name:'" + station + "',data:" + yValue + "}]";

			if (listData.endsWith(",")) {
				listData = listData.substring(0, listData.length() - 1);
			}
			listData = listData + "]";
		} else {
			Set<String> set = new HashSet<String>();
			List<String> ylist = new ArrayList<String>();
			for (AirPolLiveQX aq : alist) {
				set.add(aq.getStationName());
			}
			for (String s : set) {

				for (AirPolLiveQX aq : alist) {
					if (!aq.getStationName().equals(s))
						continue;
					DateTime dt = new DateTime(aq.getObservTime());
					Field field = AirPolLiveQX.class.getDeclaredField(ele);
					xValue += "'" + dt.toDateTimeString("yyyy-MM-dd HH") + "',";
					field.setAccessible(true);

					yValue += field.get(aq) + ",";

					// 列表数据
					listData += "{\"stationId\":\"" + aq.getStationID() + "\",\"stationName\":\"" + aq.getStationName()
							+ "\",\"dateChar\":\"" + dt.toDateTimeString() + "\",\"other\":\"" + field.get(aq) + "\"},";
				}
				if (xValue.endsWith(",")) {
					xValue = xValue.substring(0, xValue.length() - 1);
				}
				xValue = xValue + "]";
				if (yValue.endsWith(",")) {
					yValue = yValue.substring(0, yValue.length() - 1);
				}
				yValue = yValue + "]";
				yValue = "{name:'" + s + "',data:" + yValue + "},";
				x = xValue;
				ylist.add(yValue);
				yValue = "[";
				xValue = "[";
			}
			for (String s1 : ylist) {
				yValue += s1;
			}
			if (yValue.endsWith(",")) {
				yValue = yValue.substring(0, yValue.length() - 1);
			}
			yValue = yValue + "]";
			xValue = x;

			if (listData.endsWith(",")) {
				listData = listData.substring(0, listData.length() - 1);
			}
			listData = listData + "]";
		}
		if (!xValue.endsWith("]")) {
			xValue = "[" + xValue + "]";
		}
		ytitle = "['" + ytitle + "']";
		String temp = xValue + "|" + yValue + "|" + ytitle + "|" + title + "|['" + type.trim() + "']|" + listData;
		return temp;
	}


	/**
	 * 查询气象要素最新时间
	 *
	 * @return
	 */
	@RequestMapping("/liveInitTime")
	@ResponseBody
	public List<Object> liveInitTime() {
		ArrayList<Object> objects = new ArrayList<>();
		Date dt = serviceI.liveInitTime();
		DateTime date = new DateTime(dt);
		DateTime time = date.AddHours(-7);
		String startTime="2024-11-18 09:00:00";
		String endTime="2024-11-20 09:00:00";
		/*objects.add(date.toDateTimeString());
		objects.add(time.toDateTimeString());*/
		objects.add(startTime);
		objects.add(endTime);
		return objects;
	}
}
